<?php

namespace App\Models\finance;

use App\Models\AdminModel;
use App\Models\AgentModel;
use App\Models\OrderModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property int $id ID
 * @property string $declaration_date 报关日期
 * @property int $type 进口/出口(1,2)
 * @property string $plate_number 车牌
 * @property string $six_link_form 六联单
 * @property string $company_name 公司名称
 * @property string $goods_name 货物名称
 * @property string $declaration_form 报关单
 * @property int $package_num 件数
 * @property decimal $weight 重量
 * @property decimal $declaration_fee 报关费
 * @property decimal $continuation_fee 续页费
 * @property decimal $manifest_fee 舱单费
 * @property decimal $verification_list 核注清单
 * @property decimal $total_rmb 合计RMB
 * @property int $order_id 入仓单ID
 * @property int $agent_id 代理商ID
 * @property int $status 状态：1未付款 2部分付款 3已付款
 * @property decimal $pay_amount 已付金额
 * @property string $remarks 备注
 * @property int $created_admin_id 创建人ID
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 * @property string $deleted_at 删除时间
 */
class PayableDeclarationModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_payble_declaration';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    // 进口/出口类型
    const TYPE_IMPORT = 1; // 进口
    const TYPE_EXPORT = 2; // 出口

    const TYPE_LIST = [
        self::TYPE_IMPORT => '进口',
        self::TYPE_EXPORT => '出口',
    ];

    // 状态常量
    const STATUS_UNPAID = 1;      // 未付款
    const STATUS_PART_PAID = 2;   // 部分付款
    const STATUS_PAID = 3;        // 已付款

    const STATUS_LIST = [
        self::STATUS_UNPAID => '未付款',
        self::STATUS_PART_PAID => '部分付款',
        self::STATUS_PAID => '已付款',
    ];

    // 关联入仓单
    public function order(): BelongsTo 
    {
        return $this->belongsTo(OrderModel::class, 'order_id');
    }

    // 关联代理商
    public function agent(): BelongsTo 
    {
        return $this->belongsTo(AgentModel::class, 'agent_id');
    }

    // 关联创建人
    public function createAdmin(): BelongsTo 
    {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }
} 